package com.project.weather.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.project.weather.dao.SearchCityMapper;
import com.project.weather.pojo.SearchCityBean;
import com.project.weather.service.SearchCityService;
import com.project.weather.common.PageBean;
import com.project.weather.common.AResultCode;
import com.project.weather.common.ResultMap;
import com.project.weather.utils.StringUtil;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *<p>Title:SearchCityServiceImpl.java</p>
 *<p>Description:城市查询信息表ServiceImpl</p>
 *@author xxx
 *@version 1.0
 *@Automatically generate by Coder in 2021-12-21 16:07
 */
@Service
public class SearchCityServiceImpl implements SearchCityService{
	private static final Logger log = LoggerFactory.getLogger(SearchCityServiceImpl.class);
	@Autowired
	private SearchCityMapper searchCityMapper;
	
	@Override
	public ResultMap<AResultCode, SearchCityBean> insert(SearchCityBean bean){
		ResultMap<AResultCode, SearchCityBean> result = new ResultMap<AResultCode, SearchCityBean>();
		if(StringUtil.isNull(bean)){
			result.setCode(AResultCode.IS_NULL);
		} else {
//			if(StringUtil.isNull(bean.getId())){
//				bean.setId(StringUtil.getUUID());
//			}
			searchCityMapper.insertSelective(bean);	
			result.setCode(AResultCode.OK);
			result.setResult(bean);
		}
		return result;
	}

	
	@Override
	public ResultMap<AResultCode, SearchCityBean> update(SearchCityBean bean){
		ResultMap<AResultCode, SearchCityBean> result = new ResultMap<AResultCode, SearchCityBean>();

		if(StringUtil.isNull(bean)){
			result.setCode(AResultCode.IS_NULL);
		} else if(StringUtil.isNull(bean.getId())){
			result.setCode(AResultCode.MISS_ID);
		} else {
			searchCityMapper.updateSelective(bean);	
			result.setCode(AResultCode.OK);
			result.setResult(bean);
		}

		return result;
	}

	
	@Override
	public ResultMap<AResultCode, SearchCityBean> delete(String id){
		ResultMap<AResultCode, SearchCityBean> result = new ResultMap<AResultCode, SearchCityBean>();

		if(StringUtil.isNull(id)){
			result.setCode(AResultCode.MISS_ID);
		} else {
			String[] ids = id.split(",");
			searchCityMapper.delete(ids);
			result.setCode(AResultCode.OK);
		}

		return result;
	}

	
	@Override
	public ResultMap<AResultCode, PageBean<SearchCityBean>> pageList(PageBean<SearchCityBean> pb){
		ResultMap<AResultCode, PageBean<SearchCityBean>> result = new ResultMap<AResultCode, PageBean<SearchCityBean>>();

		pb.setData(searchCityMapper.pageList(pb));
		pb.clear();

		result.setCode(AResultCode.OK);
		result.setResult(pb);

		return result;
	}

	
	@Override
	public ResultMap<AResultCode, List<SearchCityBean>> list(SearchCityBean bean){
		ResultMap<AResultCode, List<SearchCityBean>> result = new ResultMap<AResultCode, List<SearchCityBean>>();

		List<SearchCityBean> list = searchCityMapper.list(bean);
		result.setCode(AResultCode.OK);
		result.setResult(list);

		return result;
	}

	
	@Override
	public ResultMap<AResultCode, SearchCityBean> get(String id){
		ResultMap<AResultCode, SearchCityBean> result = new ResultMap<AResultCode, SearchCityBean>();
		if(StringUtil.isNull(id)){
			result.setCode(AResultCode.MISS_ID);
		} else {
			SearchCityBean bean = searchCityMapper.get(id);
			if(bean != null) {
				result.setCode(AResultCode.OK);
				result.setResult(bean);
			} else {
				result.setCode(AResultCode.UNEXIST);
	 		}
		}
		return result;
	}

	@Override
	public ResultMap<AResultCode, PageBean<SearchCityBean>> countPageList(PageBean<SearchCityBean> pb) {
		ResultMap<AResultCode, PageBean<SearchCityBean>> result = new ResultMap<AResultCode, PageBean<SearchCityBean>>();

		pb.setData(searchCityMapper.countPageList(pb));
		pb.clear();

		result.setCode(AResultCode.OK);
		result.setResult(pb);

		return result;
	}


}